/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PriceMakerPanel.java
 *
 * Created on Aug 21, 2009, 10:48:37 AM
 */

package org.plotnikov.pricemaker.panels;

import java.awt.Component;
import javax.swing.JPanel;
import org.plotnikov.pricemaker.Session;
import org.plotnikov.pricemaker.patterns.observer.PriceList;

/**
 *
 * @author alexey
 */
public class PriceMakerPanel extends javax.swing.JPanel {

    private PriceList priceList;

    /** Creates new form PriceMakerPanel
     * @param pricelist 
     */
    public PriceMakerPanel(PriceList pricelist) {
        initComponents();
        this.priceList = pricelist;
        
        organisationControlPanel.addObserver(priceList);
        organisationNameControlPanel.addObserver(priceList);
        titleProductControlPanel.addObserver(priceList);
        productNameControlPanel.addObserver(priceList);
        otherInformationControlPanel.addObserver(priceList);
        postavchikControlPanel.addObserver(priceList);
        priceForControlPanel.addObserver(priceList);
        postavchikNameControlPanel.addObserver(priceList);
        priceControlPanel.addObserver(priceList);
        priceRublControlPanel.addObserver(priceList);
        lineControlPanel.addObserver(priceList);
        priceCopeekControlPanel.addObserver(priceList);
        dateControlPanel.addObserver(priceList);

        organisationControlPanel.setPanelName("Организация");
        organisationNameControlPanel.setPanelName("Название организации");
        titleProductControlPanel.setPanelName("Наименование товара");
        productNameControlPanel.setPanelName("Название товара");
        otherInformationControlPanel.setPanelName("Другая информация");
        postavchikControlPanel.setPanelName("Поставщик");
        priceForControlPanel.setPanelName("Цена за");
        postavchikNameControlPanel.setPanelName("Название поставщика");
        priceControlPanel.setPanelName("Кол. товара");
        priceRublControlPanel.setPanelName("Цена, рубли");
        lineControlPanel.setPanelName("Полоса");
        priceCopeekControlPanel.setPanelName("Цена, копейки");
        dateControlPanel.setPanelName("Дата");

        parseDrawObjectByPanels();

        jSpinner1.setValue(Session.getSession().getShift());
    }

    private void parseDrawObjectByPanels(){
        organisationControlPanel.setRefreshObj(priceList.getDrawObjFromHash("organisation"));
        organisationNameControlPanel.setRefreshObj(priceList.getDrawObjFromHash("organisationname"));
        titleProductControlPanel.setRefreshObj(priceList.getDrawObjFromHash("titleproduct"));
        productNameControlPanel.setRefreshObj(priceList.getDrawObjFromHash("nameproduct"));
        otherInformationControlPanel.setRefreshObj(priceList.getDrawObjFromHash("otherinfo"));
        postavchikControlPanel.setRefreshObj(priceList.getDrawObjFromHash("postavchik"));
        priceForControlPanel.setRefreshObj(priceList.getDrawObjFromHash("pricefor"));
        postavchikNameControlPanel.setRefreshObj(priceList.getDrawObjFromHash("postavchikname"));
        priceControlPanel.setRefreshObj(priceList.getDrawObjFromHash("price"));
        priceRublControlPanel.setRefreshObj(priceList.getDrawObjFromHash("pricerubl"));
        lineControlPanel.setRefreshObj(priceList.getDrawObjFromHash("line"));
        priceCopeekControlPanel.setRefreshObj(priceList.getDrawObjFromHash("pricecopeek"));
        dateControlPanel.setRefreshObj(priceList.getDrawObjFromHash("date"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanel4 = new javax.swing.JPanel();
        titleProductControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        productNameControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        otherInformationControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        priceRublControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        priceCopeekControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        lineControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        jPanel5 = new javax.swing.JPanel();
        organisationNameControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        postavchikNameControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        priceControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        dateControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        jPanel6 = new javax.swing.JPanel();
        organisationControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        postavchikControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        priceForControlPanel = new org.plotnikov.pricemaker.panels.ControlPanel();
        jLabel1 = new javax.swing.JLabel();
        jSpinner1 = new javax.swing.JSpinner();

        setName("Form"); // NOI18N

        jTabbedPane2.setName("jTabbedPane2"); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        titleProductControlPanel.setName("titleProductControlPanel"); // NOI18N

        productNameControlPanel.setName("productNameControlPanel"); // NOI18N

        otherInformationControlPanel.setName("otherInformationControlPanel"); // NOI18N

        priceRublControlPanel.setName("priceRublControlPanel"); // NOI18N

        priceCopeekControlPanel.setName("priceCopeekControlPanel"); // NOI18N

        lineControlPanel.setName("lineControlPanel"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(titleProductControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(productNameControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(otherInformationControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(priceRublControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(priceCopeekControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lineControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(titleProductControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(productNameControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(otherInformationControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(priceRublControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(priceCopeekControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lineControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(org.plotnikov.pricemaker.PriceMakerApp.class).getContext().getResourceMap(PriceMakerPanel.class);
        jTabbedPane2.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        organisationNameControlPanel.setName("organisationNameControlPanel"); // NOI18N

        postavchikNameControlPanel.setName("postavchikNameControlPanel"); // NOI18N

        priceControlPanel.setName("priceControlPanel"); // NOI18N

        dateControlPanel.setName("dateControlPanel"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(organisationNameControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(postavchikNameControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(priceControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(dateControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(organisationNameControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(postavchikNameControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(priceControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(dateControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(141, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab(resourceMap.getString("jPanel5.TabConstraints.tabTitle"), jPanel5); // NOI18N

        jPanel6.setName("jPanel6"); // NOI18N

        organisationControlPanel.setName("organisationControlPanel"); // NOI18N

        postavchikControlPanel.setName("postavchikControlPanel"); // NOI18N

        priceForControlPanel.setName("priceForControlPanel"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel6Layout.createSequentialGroup()
                        .add(organisationControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(postavchikControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(priceForControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(organisationControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(postavchikControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(priceForControlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(141, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab(resourceMap.getString("jPanel6.TabConstraints.tabTitle"), jPanel6); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jSpinner1.setModel(new javax.swing.SpinnerNumberModel(2, 1, 10, 1));
        jSpinner1.setName("jSpinner1"); // NOI18N
        jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinner1StateChanged(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jTabbedPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 453, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(327, Short.MAX_VALUE)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSpinner1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 56, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jTabbedPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 449, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jSpinner1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged
        Session.getSession().setShift((Integer)jSpinner1.getValue());
        fireControlPanels(jPanel4);
        fireControlPanels(jPanel5);
        fireControlPanels(jPanel6);
    }//GEN-LAST:event_jSpinner1StateChanged

    private void fireControlPanels(JPanel panel){
        int move = ((Integer)jSpinner1.getValue()).intValue();
        Component[] comps = panel.getComponents();
        for (int i = 0; i < comps.length; i++) {
            Component component = comps[i];
            if (component instanceof ControlPanel){
                ControlPanel p = (ControlPanel) component;
                p.setMovePixels(move);
            }
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.plotnikov.pricemaker.panels.ControlPanel dateControlPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private org.plotnikov.pricemaker.panels.ControlPanel lineControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel organisationControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel organisationNameControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel otherInformationControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel postavchikControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel postavchikNameControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel priceControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel priceCopeekControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel priceForControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel priceRublControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel productNameControlPanel;
    private org.plotnikov.pricemaker.panels.ControlPanel titleProductControlPanel;
    // End of variables declaration//GEN-END:variables

}
